local CommonOHOH = _G.CommonOHOH;
local M = CommonOHOH.class.new(script, CommonOHOH.files.BaseComponent());
local CallBackManager = CommonOHOH.load.CallBackManager();

--控制武器的输入
function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)

	M.super.ctor(self, parent)
    self.player=self.parent.player
    self.character=self.parent.character
    self.weapon=self.parent
    self.weaponLevel=self.weapon:GetLevel()
    self.cfg=self.weapon:GetCfg()
    self:AddMonitor()
end;


function M.dtor(self)
	M.super.dtor(self);
end;

function M.AddMonitor(self)

    --触发获取攻击cd
    CallBackManager:AddRbxConnect(self,self.weapon.AttackCdEvent, function()
            local list=self.player.GetAttackCDEvent:Action()
            local sum=0
            for _,v in pairs(list) do
                sum=sum+v
            end
            return sum
    end);


    --触发获取攻击力
    CallBackManager:AddRbxConnect(self,self.weapon.AttackDamgeEvent, function()
            local list=self.player.GetAttackDamgeEvent:Action(self)
            local dt=0
            for _,v in pairs(list) do
                dt=dt+v
            end
            return dt
    end);

    --获取攻击目标
    CallBackManager:AddRbxConnect(self,self.weapon.FindTagEvent, function()
            local list= self.player.FindAttackTargetEvent:Action(self.character,self.player)
            for k,v in pairs(list) do
                return v
            end
    end);

    -- 伤害监听（客户端产生伤害）
    self.parent.PushDamgeEvent:Connect(function(obj,player,arriveEvent,sendInfo)
        if obj then --存在射击对象，子弹到达终点后，造成伤害
            obj:PushDamge(self.parent:GetDamge(),player,arriveEvent,sendInfo)--伤害值，延迟事件
        end
    end)
    

------------------------------------------------------------------------------------------
    -- 训练cd
    CallBackManager:AddRbxConnect(self,self.player.TrainCdBaseEvent, function()
        return self.weapon:GetBaseCd()
   end);

   --打怪cd
   CallBackManager:AddRbxConnect(self,self.player.AttackCdBaseEvent, function()
        return self.weapon:GetBaseCd()
   end);


   --训练伤害
   CallBackManager:AddRbxConnect(self,self.player.TrainValueBaseEvent, function()

        return self.weapon:GetBaseDamge()
  end);


    --打怪伤害
    CallBackManager:AddRbxConnect(self,self.player.AttackValueBaseEvent, function()

            return self.weapon:GetBaseDamge()
    end);



end

return M

